classicube_sys\vectors\ivec/
mod.rs

1mod ops;
2
3use crate::{
4    bindings::{IVec3, Vec3},
5    std_types::c_int,
6    Int32_MaxValue, Vec3_IsZero, Vec3_Set,
7};
8
9impl IVec3 {
10    pub const fn new(x: c_int, y: c_int, z: c_int) -> Self {
11        Self { x, y, z }
12    }
13
14    pub const fn zero() -> Self {
15        Self { x: 0, y: 0, z: 0 }
16    }
17
18    pub fn set(&mut self, x: c_int, y: c_int, z: c_int) {
19        Vec3_Set!(self, x, y, z);
20    }
21
22    pub fn is_zero(&self) -> bool {
23        Vec3_IsZero!(self)
24    }
25
26    pub const fn max_value() -> Self {
27        IVec3_MaxValue()
28    }
29
30    pub fn to_vec3(&self) -> Vec3 {
31        let mut result = Vec3::zero();
32        IVec3_ToVec3(&mut result, self);
33        result
34    }
35
36    #[must_use]
37    pub fn min(&self, b: IVec3) -> Self {
38        let mut result = Self::zero();
39        IVec3_Min(&mut result, self, &b);
40        result
41    }
42
43    #[must_use]
44    pub fn max(&self, b: IVec3) -> Self {
45        let mut result = Self::zero();
46        IVec3_Max(&mut result, self, &b);
47        result
48    }
49}
50
51impl From<IVec3> for Vec3 {
52    fn from(other: IVec3) -> Self {
53        other.to_vec3()
54    }
55}
56
57/// Returns a vector with all components set to Int32_MaxValue.
58pub const fn IVec3_MaxValue() -> IVec3 {
59    IVec3 {
60        x: Int32_MaxValue,
61        y: Int32_MaxValue,
62        z: Int32_MaxValue,
63    }
64}
65
66pub fn IVec3_ToVec3(result: &mut Vec3, a: &IVec3) {
67    result.x = a.x as _;
68    result.y = a.y as _;
69    result.z = a.z as _;
70}
71
72pub fn IVec3_Min(result: &mut IVec3, a: &IVec3, b: &IVec3) {
73    result.x = a.x.min(b.x);
74    result.y = a.y.min(b.y);
75    result.z = a.z.min(b.z);
76}
77
78pub fn IVec3_Max(result: &mut IVec3, a: &IVec3, b: &IVec3) {
79    result.x = a.x.max(b.x);
80    result.y = a.y.max(b.y);
81    result.z = a.z.max(b.z);
82}